package com.pdf;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.pdf.DemoPDF;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 添加page页
 *
 * @author liyiruo
 * @Description
 * @Date 2021/8/10 下午4:35
 */
public class ManyPagePDF {
    public static void main(String[] args) throws DocumentException, FileNotFoundException {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DemoPDF.path + "ManyPagePDF.pdf"));

        document.open();
        document.add(new Paragraph("First page-ManyPagePDF\n"));
        document.add(new Paragraph(String.valueOf(document.getPageSize())));
        //新增一页不写内容
        document.newPage();
        writer.setPageEmpty(false);
        //再新增一页
        document.newPage();
        document.add(new Paragraph("New page-ManyPagePDF"));
        document.close();
    }
}
